﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mimoza.Plugins.DisplaySettings
{
    public class LX_ExecutePlugin : BaseExecutePlugin
    {
        #region BaseExecutePlugin Members

        public override string Id
        {
            get { return this.ToString(); }
        }

        public override bool Add(Mimoza.ObjectLayer.Policy policy, DisplayResolution data)
        {
            return Apply(policy, data);
        }

        public override bool Remove(Mimoza.ObjectLayer.Policy policy, DisplayResolution data)
        {
            return false;
        }

        public override bool Update(Mimoza.ObjectLayer.Policy policy, DisplayResolution data)
        {
            return Apply(policy, data);
        }

        #endregion

        bool Apply(Mimoza.ObjectLayer.Policy policy, DisplayResolution data)
        {
            string settingString = GetSettingsString(data);
            object colorDepth = data.ColorDepthAsInt;

            Common.Logger.Log.Trace("Mimoza.Plugins.DisplaySettings.LX_ExecutePlugin.Apply settingString - '{0}' colorDepth - {1}",
                    settingString, colorDepth.ToString());

            Common.Instrumental.Registry registry = new Mimoza.Common.Instrumental.Registry("Software\\Geode");

            registry.CheckAndRewrite("Resolution", settingString);
            registry.CheckAndRewrite("FrameBufferDepth", colorDepth);

            return registry.IsModified;
        }

        string GetSettingsString(DisplayResolution data)
        {
            return data.Width.ToString() + " " + data.Height.ToString() + " " + data.Freq.ToString();
        }
    }
}
